<template>
  <div class="content-block block-half-1">
    <div class="info-head">{{ title }}</div>
    <div class="info-content">
      <v-chart
        :option="chartOption" style="width: 100%;height: 470px;"
        :theme="chartTheme" autoresize
      ></v-chart>
    </div>
  </div>
</template>

<script>
import { createMonthRangeOfYear, getEnergyUnitName } from '@/utils'
import MixinVchartTheme from '@/mixins/mixin-vchart-theme';

export default {
  name: 'grid-item-three',
  mixins: [MixinVchartTheme],
  props: {
    title: String,
    info: {
      type: Array,
      default () {
        return []
      }
    }
  },
  computed: {
    energyVariety () {
      return this.$store.state.energyVariety
    },
    chartOption () {
      const info = this.info
      const legendData = this.energyVariety.map(v => v.name)
      return {
        legend: {
          top: 'bottom',
          data: legendData
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross'
          }
        },
        grid: {
          left: '8%',
          right: '8%',
          bottom: 60
        },
        xAxis: {
          type: 'category',
          data: createMonthRangeOfYear()
        },
        yAxis: {
          type: 'value',
        },
        series: [
          ...this.energyVariety.map((v, i) => ({
            name: legendData[i],
            type: 'line',
            smooth: true,
            data: info[i],
            tooltip: {
              valueFormatter: value => `${value || '-'} ${getEnergyUnitName(v.value)}`
            }
          }))
        ]
      }
    }
  }
}
</script>

<style scoped>

</style>
